#include <iostream>
#include "../head/TreeNode.h"

using namespace std;

// 111: Minmum Depth of Binary Tree
class Solution {
public:
    int maxDepth(TreeNode* root) {
		if(root == NULL){
            return 0;
        }
        
        queue<TreeNode*> q;
        int result = 1;
        q.push(root);
        
        while(!q.empty()){
            int count = q.size();

            while(count > 0){
                TreeNode *tmp = q.front();
                
                if(tmp->left == NULL && tmp->right == NULL){
                    return result;
                }
                
                q.pop();
                
                if(tmp->left != NULL){
                    q.push(tmp->left);
                }
                if(tmp->right != NULL){
                    q.push(tmp->right);
                }
                
                count--;
            }
            
            result++;
        }
        
        return result;
    }
};
